import request from '@/utils/request';

export async function getOrderList(companyId, page) {
    // return await request.post('/api/1.0/base/b611020companyorder/list', {
    return await request.post('/api/1.0/company/order/search', {
        companyId: companyId,
        pageCurrent: page
    });
}

export async function getHSoptions(hsCode, type) {
    if (type == 1) {
        return await request.post('/api/1.0/base/m811010commodityinfo/list', {
            hsName: hsCode,
            orderby:'create_time desc'


        });
    } else {
        return await request.post('/api/1.0/base/m811010commodityinfo/list', {
            hsCode: hsCode,
            orderby:'create_time desc'
        });
    }
}

export async function getHSInfo(hsCode) {
    return await request.post('/api/1.0/base/m811010commodityinfo/info', {
        hsCode: hsCode
    });
}

export async function getOrderInfoPost(orderID) {
    return await request.post('/api/1.0/base/b611020companyorder/info', {
        id: orderID
    });
}

export async function getOrderDetailInfoPost(orderID, page) {
    return await request.post('/api/1.0/base/b611030companyorderproduct/list', {
        refOrderId: orderID,
        pageCurrent: page,
        pageLimit:10000
    });
}

export async function getOrderInfo3001(orderType) {
    var typeModel = '3001' + orderType;
    if (!localStorage.hasOwnProperty(typeModel)) {
        return JSON.parse(localStorage.getItem(typeModel));
    } else {
        return await request.post('/api/1.0/base/s901060parameter/list', {
            configTypeId: orderType,
            delFlag: 0,
            pageLimit: 1000,
            orderby:'create_time desc'
        });
    }
}

export async function getOrderInfo3002() {
    var typeModel = '3002';
    if (localStorage.hasOwnProperty(typeModel)) {
        return JSON.parse(localStorage.getItem(typeModel));
    } else {
        return await request.post('/api/1.0/base/m812050cbinfo/list', {
            delFlag: 0,
            pageLimit: 5000
        });
    }
}

//港口查询
export async function getOrderInfo3003() {
    var typeModel = '3003';
    if (localStorage.hasOwnProperty(typeModel)) {
        return JSON.parse(localStorage.getItem(typeModel));
    } else {
        return await request.post('/api/1.0/base/M812060PtInfoCustom/list', {
            delFlag: 0,
            pageLimit: 5000
        });
    }
}

export async function getOrderInfo3001L(orderType) {
    var token = '';
    if (localStorage.hasOwnProperty('token')) {
        token = localStorage.getItem('token');
        return await request.post('/api/1.0/base/s901060parameter/list', {
            token: token,
            configTypeId: orderType,
            delFlag: 0,
            orderby:'create_time desc',
            pageLimit: 1000
        });
    } else {
        return await request.post('/api/1.0/base/s901060parameter/list', {
            configTypeId: orderType,
            delFlag: 0,
            pageLimit: 1000,
            orderby:'create_time desc'
        });
    }
}

export async function getOrderInfo3002L() {
    var token = '';
    if (localStorage.hasOwnProperty('token')) {
        token = localStorage.getItem('token');
        return await request.post('/api/1.0/base/m812050cbinfo/list', {
            token: token,
            delFlag: 0,
            pageLimit: 5000
        });
    } else {
        return await request.post('/api/1.0/base/m812050cbinfo/list', {
            delFlag: 0,
            pageLimit: 5000
        });
    }
}

//港口查询
export async function getOrderInfo3003L() {
    var token = '';
    if (localStorage.hasOwnProperty('token')) {
        token = localStorage.getItem('token');
        return await request.post('/api/1.0/base/M812060PtInfoCustom/list', {
            token: token,
            delFlag: 0,
            pageLimit: 5000
        });
    } else {
        return await request.post('/api/1.0/base/M812060PtInfoCustom/list', {
            delFlag: 0,
            pageLimit: 5000
        });
    }
}

export async function getHScode(code) {
    return await request.post('/api/1.0/base/s901060parameter/list', {
        configTypeId: code,
        orderby:'create_time desc'
    });
}

export async function getOrderSearch(beginDate, endDate, type, page, orderCodeCmp) {
    return await request.post('/api/1.0/company/order/search', {
        beginDate: beginDate,
        endDate: endDate,
        applicationState: type,
        pageCurrent: page,
        orderCodeCmp
    });
}

export async function getOrderCount(companyId) {
    return await request.post('/api/1.0/company/order/orderNum/get', {
        companyId: companyId
    });
}

/**
 * 一键出货
 * @param id
 * @param type
 * @returns {Promise<*>}
 */
export let oneExport = async (id,type)=>{
    return await request.post('/api/1.0/base/b611020companyorder/modify', {
        id: id,
        applicationState: type,
        token:localStorage.getItem('token')
    });
}
export async function updataOrderInfo(
    orderid,
    isNew,
    orderCodeCmp, // orderCodeCmp	[string]	是	企业订单编号
    orderName, // orderName	[string]	是	订单名称
    foreignBusi, // foreignBusi	[string]	是	外商名称
    foreignCountry, // foreignCountry	[string]	是	外商国别
    declareCustoms, // declareCustoms	[string]	是	报关地海关
    portLoading, // portLoading	[string]	是	起运港
    arrivalCountry, // arrivalCountry	[string]	是	抵运国
    portDestination, // portDestination	[string]	是	目的港
    tradeMode, // tradeMode	[string]	是	贸易方式
    priceClause, // priceClause	[string]	是	价格条款
    packingMode, // packingMode	[string]	是	包装方式
    transportMode, // transportMode	[string]	是	运输方式
    orderCurrency, // orderCurrency	[string]	是	订单币种
    receiptMode, // receiptMode	[string]	是	收汇方式
    transportPaymentMode, // transportPaymentMode	[string]	是	运输支付方式
    isInsure, // isInsure	[string]	是	是否投保中信保 1没投过，2投过
    applicationState, // applicationState	[string]	是	申报状态 1未申报，2已申报
    deliveryTime, // deliveryTime	[string]	是	交货日期
    orderTime, // orderTime	[string]	是	订单日期
    orderdetails,
    meno,
    fb4,
    fb1
) {
    if (!isNew) {
        return await request.post('/api/1.0/company/order/upload', {
            orderCodeCmp: orderCodeCmp,
            orderName: orderName,
            foreignBusi: foreignBusi,
            foreignCountry: foreignCountry,
            declareCustoms: declareCustoms,
            portLoading: portLoading,
            arrivalCountry: arrivalCountry,
            portDestination: portDestination,
            tradeMode: tradeMode,
            priceClause: priceClause,
            packingMode: packingMode,
            transportMode: transportMode,
            orderCurrency: orderCurrency,
            receiptMode: receiptMode,
            transportPaymentMode: transportPaymentMode,
            isInsure: isInsure,
            applicationState: applicationState,
            deliveryTime: deliveryTime,
            orderTime: orderTime,
            products: orderdetails,
            meno: meno,
            fb4,
            fb1
        });
    } else {
        return await request.post('/api/1.0/company/order/upload', {
            id: orderid,
            orderCodeCmp: orderCodeCmp,
            orderName: orderName,
            foreignBusi: foreignBusi,
            foreignCountry: foreignCountry,
            declareCustoms: declareCustoms,
            portLoading: portLoading,
            arrivalCountry: arrivalCountry,
            portDestination: portDestination,
            tradeMode: tradeMode,
            priceClause: priceClause,
            packingMode: packingMode,
            transportMode: transportMode,
            orderCurrency: orderCurrency,
            receiptMode: receiptMode,
            transportPaymentMode: transportPaymentMode,
            isInsure: isInsure,
            applicationState: applicationState,
            deliveryTime: deliveryTime,
            orderTime: orderTime,
            products: orderdetails,
            meno: meno,
            fb4,
            fb1
        });
    }
}

export let copyOrderFn = async (id, token) => {
    return request.post('/api/1.0/company/order/copy/companyorder', {
        token: localStorage.getItem('token'),
        id: id
    })
}

